package org.jeecg.modules.lab.cronJob.service.impl;

import org.jeecg.common.cronJob.entity.LabCronJob;
import org.jeecg.modules.lab.cronJob.mapper.LabCronJobMapper;
import org.jeecg.modules.lab.cronJob.service.ILabCronJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 数据同步定时任务表
 * @Author: jeecg-boot
 * @Date: 2023-11-21
 * @Version: V1.0
 */
@Service
public class LabCronJobServiceImpl extends ServiceImpl<LabCronJobMapper, LabCronJob> implements ILabCronJobService {


    @Override
    public void saveCronBatch(String tableName, String flag, Long time, String[] ids) {
        List<LabCronJob> jobs = new ArrayList<>();
        for (int i = 0; i < ids.length; i++) {
            String condition = "id='" + ids[i] + "'";
            jobs.add(new LabCronJob("lab_device", flag, condition, time, i + 1));
        }
        super.saveBatch(jobs);
    }

    @Override
    public void saveCron(String tableName, String flag, Long time, String id) {
        String condition = "id='" + id + "'";
        LabCronJob job = new LabCronJob("lab_enterprise", flag, condition, time, 1);
        super.save(job);
    }

    @Override
    public void saveCronBatchA(String lab_items_device, String flag, long time, String[] ids) {
        List<LabCronJob> jobs = new ArrayList<>();
        for (int i = 0; i < ids.length; i++) {
            String condition = "item_id='" + ids[i] + "'";
            jobs.add(new LabCronJob("lab_items_device", flag, condition, time, i + 1));
        }
        super.saveBatch(jobs);
    }
}
